import java.util.List;


public class Main {

	/**
	 * @param args
	 * @throws InterruptedException 
	 */
	public static void main(String[] args) throws InterruptedException {
		
		
		User newUser1 = new User("0", "jack0", new Location(-10, 80));
		User newUser2 = new User("1", "jack1", new Location(145, -50));
		User newUser3 = new User("2", "jack2", new Location(-12, 5));
		User newUser4 = new User("3", "jack3", new Location(130, -50));
		User newUser5 = new User("4", "jack4", new Location(-14, 22));
		User newUser6 = new User("5", "jack5", new Location(101, -40));
		
		
		
		MongoDAO.getInstance().AddUser(newUser1);
		MongoDAO.getInstance().AddUser(newUser2);
		MongoDAO.getInstance().AddUser(newUser3);
		MongoDAO.getInstance().AddUser(newUser4);
		MongoDAO.getInstance().AddUser(newUser5);
		MongoDAO.getInstance().AddUser(newUser6);
	
		
		TextContent bla = new TextContent();
		bla.text = "hello";
		
	
		
		User b = MongoDAO.getInstance().GetUserByNickName("jack0");
		User c = MongoDAO.getInstance().GetUserByNickName("jack5");
		
		//MongoDAO.getInstance().AddMessage(newMessage);
		List<User> users = MongoDAO.getInstance().GetAllUsers();	
		
		Message mb = new Message();
		mb.startLocation = b.location;
		mb.iterationsLeft = 5;
		mb.destination = "5";
		mb.id ="1";
		mb.currentMessageHolder = b.identity;
		
		Message mc = new Message();
		mc.startLocation = b.location;
		mc.iterationsLeft = 5;
		mc.destination = "5";
		mc.id ="2";
		mc.currentMessageHolder = b.identity;
		
		Message md = new Message();
		md.startLocation = b.location;
		md.iterationsLeft = 5;
		md.destination = "5";
		md.id ="3";
		md.currentMessageHolder = b.identity;
		
		b.AuthorNewMessage(mb);
		b.AuthorNewMessage(mc);
		b.AuthorNewMessage(md);
		//c.Send(c.messages.get(0));
		//c.Send(c.messages.get(0));
		
		users = MongoDAO.getInstance().GetAllUsers();

		for(int i = 0; i < 5; ++i) {
		for (User s: users)
		{
			for (int j = 0; j < s.messages.size(); j++)
				if(s.GetNextRecipient(s.messages.get(j)) != null) {
					s.Send(s.messages.get(j), s.GetNextRecipient(s.messages.get(j)));
				}
			users = MongoDAO.getInstance().GetAllUsers();
		}

		}

		//User j = MongoDAO.getInstance().GetUserById("1");
		//j.Send(j.messages.get(0));
		
		
		/*users = MongoDAO.getInstance().GetAllUsers();
		for (User s : users)
			System.out.println(s.identity+": "+s.messages.size());*/
	
		Thread.sleep(1000);
		users = MongoDAO.getInstance().GetAllUsers();
		for (User s : users)
		{
			System.out.println(s.identity+" "+s.messages.size());
			//if (s.messages.size() > 0)
			
		}
	}

}
